package com.xxxx.server.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxxx.server.mapper.SleaveMapper;
import com.xxxx.server.pojo.Admin;
import com.xxxx.server.pojo.RespPageBean;
import com.xxxx.server.pojo.Sleave;
import com.xxxx.server.service.ISleaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 学生请假表 服务实现类
 * </p>
 *
 * @author zhoubin
 * @since 2022-06-02
 */
@Service
public class SleaveServiceImpl extends ServiceImpl<SleaveMapper, Sleave> implements ISleaveService {

    @Autowired
    private SleaveMapper sleaveMapper;

    @Override
    public List<Sleave> getSleaveBySlId() {
        return sleaveMapper.getSleaveBySlId(((Admin) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getId());
    }

    @Override
    public RespPageBean getStuleaveByPage(Integer currentPage, Integer size, Sleave sleave, String[] beginDateScope,int type,String collegename,int collegeid,String classname,int classid) {
        //开启分页
        Page<Sleave> page = new Page<>(currentPage,size);
        IPage<Sleave> sleaveByPage = sleaveMapper.getStuleaveByPage(page, sleave, beginDateScope,type,collegename,collegeid,classname,classid);
        RespPageBean respPageBean = new RespPageBean(sleaveByPage.getTotal(), sleaveByPage.getRecords());
        return respPageBean;

    }

    @Override
    public List<Sleave> getSleave(Integer id) {
        return sleaveMapper.getSleave(id);
    }
}
